package message;

import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.util.function.Function;
import java.util.function.Consumer;

public class BasicMessageBuilder extends AbstractMessageBuilder{
	protected Function<? super ByteBuffer, ? extends Object> getter;
	public BasicMessageBuilder(Consumer<? super Object> callback, Function<? super ByteBuffer, ? extends Object> getter) {
		super(callback);
		this.getter = getter;
	}
	@Override
	public boolean read(ByteBuffer byteBuffer) {
		try {
			this.build = getter.apply(byteBuffer);
		} catch (BufferUnderflowException e) {
			return false;
		}
		return super.read(byteBuffer);
	}
	
}
